<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>修改密码</title>
    <!-- Bootstrap -->
    <link href="../js/bootstrap/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>

<div class="container" >
    <div id="errorDiv" class="bg-info"></div>
    <div class="row">
        <div class="col-md-12">
            <form class="form-horizontal" >


                <div class="form-group">
                    <label  class="col-sm-2 control-label">老密码:</label>
                    <div class="col-sm-4">
                        <input type="password" name="oldPassword" class="form-control" id="oldPassword" placeholder="请输入老密码">
                    </div>
                    <div id="oldPasswordTip"></div>
                </div>

                <div class="form-group">
                    <label  class="col-sm-2 control-label">密码:</label>
                    <div class="col-sm-4">
                        <input type="password" name="password" class="form-control" id="password" placeholder="请输入新密码">
                    </div>
                    <div id="passwordTip"></div>
                </div>

                <div class="form-group">
                    <label  class="col-sm-2 control-label">确认密码:</label>
                    <div class="col-sm-4">
                        <input type="password" name="confirmPassword" class="form-control" id="confirmPassword" placeholder="请输入确认新密码">
                    </div>
                    <div id="confirmPasswordTip"></div>
                </div>

                <div style="text-align: center;">
                    <button type="button" class="btn btn-primary" id="regButton" onclick="updatePassword()" >修改密码</button>
                    <button type="reset" class="btn btn-default">重置</button>
                </div>
            </form>
        </div>
    </div>
</div>


<!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
<script src="../js/jquery-3.3.1.js"></script>
<!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
<script src="../js/bootstrap/js/bootstrap.min.js"></script>
<!--引入封装好的cookie-->
<script src="../js/jquery.cookie.min.js"></script>

<script src="../js/common.js"></script>
</body>

<script>


    /**
     * 找回密码
     */
    function updatePassword(){
        var param = {};
        // 获取密码
        param.password = $("#password").val().trim();
        // 获取老密码
        param.oldPassword = $("#oldPassword").val().trim();
        // 获取确认密码
        param.confirmPassword = $("#confirmPassword").val().trim();
        $.post({
            data:param,
            url:server_url+"/member/updatePassword",
            beforeSend:function (xhr){
                let v_token=$.cookie("token");
                xhr.setRequestHeader("x-auth",v_token);
            },
            success:function(result){
                if(result.code==200){
                    //删除cookic
                    $.removeCookie("token");
                    alert("修改成功，请登录！");
                    location.href = "login.html";
                }else if(result.code!=200){
                    alert(result.msg);
                }
            },
            error:function(){
                alert("发送请求失败");
            }
        })

    }

</script>

</html>
